package day06;

import java.util.Scanner;

/*
 *  需求：《主持人大赛》有N位评委给选手打分
 *      选手的最终得分为：去掉最高分和最低分之后的N-2位评委的平均分
 *   要求：使用方法实现
 */
public class CalTotalAvg {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("输入共有几位评委：");
        double sum ;
        sum = sum(scan.nextInt());
        System.out.println("总分是："+sum);
    }
    //录入评委成绩
    public static double[] inputData(int n){
        Scanner scan = new Scanner(System.in);
        double[] scores = new double[n];
        for (int i = 0;i<scores.length;i++){
            System.out.println("请输入第" + (i+1) + "位评委的分数：");
            scores[i]= scan.nextDouble();
        }
        return scores;
    }
    //计算平均分、总分的
    public static double sum (int n){
        double sum =0;
        double avg =0;
        double[] scores=inputData(n);
        double max = scores[0];
        for (int i = 0;i<scores.length;i++){
            if (scores[i]>max){
                max=scores[i];
            }
        }
        double min = scores[0];
        for (int i= 0;i<scores.length;i++){
            if (scores[i]<min){
                min = scores[i];
            }
        }
        for (int i = 0;i<scores.length;i++){
            sum = sum + scores[i];
        }
        System.out.println("最高分是："+max+"    最低分是："+min);
        sum = sum -max -min;
        avg = sum /(n-2);
        System.out.println("平均分是："+avg);
        return sum;
    }

}
